// D3D9Device.h

#ifndef __D3D9DEVICE_H__
#define __D3D9DEVICE_H__

#include "d3d9.h"
#include "d3dx9.h"

#include "..\Core\Singleton.h"

class CD3D9RenderUnit;
class CD3D9Device : public Singleton<CD3D9Device>
{
public:
	struct TDisplayMode
	{
		D3DFORMAT fmt;
		unsigned int unWidth;
		unsigned int unHeight;
		unsigned int unRefreshRate;
	};
private:
	HWND m_hWnd;
	BOOL m_bWindowed;
	IDirect3D9* m_pDirect3D;
	IDirect3DDevice9* m_pDevice;
	D3DPRESENT_PARAMETERS m_d3dpp;
	TDisplayMode m_tDisplayMode;

private:
	bool RestoreDevice(void);
public:
	CD3D9Device(void);
	virtual ~CD3D9Device();

	// const method
	IDirect3DDevice9* GetDevice(void) const;

	bool CreateDevice(HWND hWnd, int nWidth, int nHeight, BOOL bWindow);
	void BeginScene(void);
	void EndScene(void);
	void Render(CD3D9RenderUnit* pUnit);
	void OnD3D9ResetDevice();
};

#endif